#include <pthread.h>
#include <stdio.h>

class MyClass {
 public:
  MyClass() {
    // 创建线程
    pthread_create(&m_threadId, NULL, &MyClass::threadFunc,
                   static_cast<void *>(&m_threadArg));
  }

  ~MyClass() {
    // 等待线程结束
    pthread_join(m_threadId, NULL);
  }

 private:
  struct ThreadArg {
    int m_memberVariable;
  };

  static void *threadFunc(void *arg) {  // 静态成员函数
    ThreadArg *threadArg = static_cast<ThreadArg *>(arg);
    int memberVariable = threadArg->m_memberVariable;
    // 继续处理后续业务逻辑。
  }

 private:
  int m_memberVariable;

 private:
  pthread_t m_threadId;
  ThreadArg m_threadArg;
};

int main() {
  MyClass obj;
  // ...
  return 0;
}
